home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / quicktime / quicktimeintro / play movie w.controller / common files / comframework.c next >
Encoding:
Text File  |  2000-10-06  |  43.1 KB  |  1,589 lines

  1. //////////
  2. //
  3. //    File:        ComFramework.c
  4. //
  5. //    Contains:    Code for the QuickTime sample code framework that is common to both Macintosh and Windows.
  6. //
  7. //    Written by:    Tim Monroe
  8. //                Based on the QTShell code written by Tim Monroe, which in turn was based on the MovieShell
  9. //                code written by Kent Sandvik (Apple DTS). This current version is now very far removed from
  10. //                MovieShell.
  11. //
  12. //    Copyright:    © 1999 by Apple Computer, Inc., all rights reserved.
  13. //
  14. //    Change History (most recent first):
  15. //       
  16. //       <15>         03/02/00    rtm        made changes to get things running under CarbonLib
  17. //       <14>         02/16/00    rtm        added QTFrame_GetWindowPtrFromWindowReference
  18. //       <13>         01/19/00    rtm        revised QTFrame_IsAppWindow (dialog windows no longer count as application
  19. //                                    windows); added QTFrame_BuildFileTypeList and QTFrame_AddComponentFileTypes
  20. //                                    to avoid calling GetMovieImporterForDataRef in QTFrame_FilterFiles; removed
  21. //                                    the hard-coded file types
  22. //       <12>         01/14/00    rtm        added support for graphics files, using graphics importers
  23. //       <11>         12/28/99    rtm        added QTFrame_ConvertMacToWinRect and QTFrame_ConvertWinToMacRect
  24. //       <10>         12/21/99    rtm        hard-coded some file types into QTFrame_FilterFiles; if we let QuickTime
  25. //                                    to do all the testing (using GetMovieImporterForDataRef), it takes too long
  26. //       <9>         12/17/99    rtm        added some code to QTFrame_SetMenuItemState to work around a problem that
  27. //                                    appears under MacOS 8.5.1 (as far as I can tell...)
  28. //       <8>         12/16/99    rtm        added QTApp_HandleMenu calls to _HandleFileMenuItem and _HandleEditMenuItem
  29. //                                    to allow the application-specific code to intercept menu item selections;
  30. //                                    added QTFrame_FilterFiles
  31. //       <7>         12/15/99    rtm        added QTApp_Idle call to QTFrame_IdleMovieWindows
  32. //       <6>         12/11/99    rtm        added GetMenuState call to Windows portion of QTFrame_SetMenuItemLabel;
  33. //                                    tweaked _SizeWindowToMovie to guard against NULL movie and/or controller
  34. //       <5>         11/30/99    rtm        added QTFrame_CloseMovieWindows
  35. //       <4>         11/27/99    rtm        added QTFrame_GetFileFilterUPP
  36. //       <3>         11/17/99    rtm        finished support for Navigation Services; added QTFrame_IdleMovieWindows
  37. //       <2>         11/16/99    rtm        begun support for Navigation Services
  38. //       <1>         11/05/99    rtm        first file
  39. //
  40. //    This file contains several kinds of functions: (1) functions that use completely cross-platform APIs and
  41. //    which therefore can be compiled and run for both Mac and Windows platforms with no changes whatsoever (a
  42. //    good example of this is QTFrame_SaveAsMovieFile); (2) functions that are substantially the same on both
  43. //    platforms but which require several short platform-dependent #ifdef TARGET_OS_ blocks (a good example of
  44. //    this is QTFrame_AdjustMenus); (3) functions that retrieve data from framework-specific data structures (a
  45. //    good example of this is QTFrame_GetWindowObjectFromWindow); (4) functions that provide a platform-neutral
  46. //    interface to platform-specific operations (a good example of this is QTFrame_Beep). In a nutshell, this
  47. //    file attempts to provide platform-independent services to its callers, typically functions in the files
  48. //    MacFramework.c, WinFramework.c, and ComApplication.c.
  49. //
  50. //    In general, you should not need to modify this file. Your application-specific code should usually be put
  51. //    into the file ComApplication.c.
  52. //
  53. //////////
  54.  
  55. //////////
  56. //
  57. // header files
  58. //
  59. //////////
  60.  
  61. #include "ComFramework.h"
  62.  
  63.  
  64. //////////
  65. //
  66. // global variables
  67. //
  68. //////////
  69.  
  70. Rect                    gMCResizeBounds;                        // maximum size for any movie window
  71. OSType                     *gValidFileTypes = NULL;                // the list of file types that our application can open
  72.  
  73. #if TARGET_OS_WIN32
  74. extern HWND                ghWnd;
  75. extern HWND                ghWndMDIClient;
  76. extern BOOL                gWeAreSizingWindow;
  77. #endif
  78.  
  79. #if TARGET_OS_MAC
  80. extern Str255            gAppName;
  81. void                    QTFrame_HandleEvent (EventRecord *theEvent);
  82. #endif
  83.  
  84.  
  85. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  86. //
  87. // Menu-handling functions.
  88. //
  89. // Use these functions to handle items in the File and Edit menus.
  90. //
  91. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  92.  
  93. //////////
  94. //
  95. // QTFrame_HandleFileMenuItem
  96. // Handle the specified File menu item.
  97. //
  98. //////////
  99.  
  100. void QTFrame_HandleFileMenuItem (WindowReference theWindow, UInt16 theMenuItem)
  101. {
  102.     // give the application-specific code a chance to intercept the menu item selection
  103.     if (QTApp_HandleMenu(theMenuItem))
  104.         return;
  105.         
  106.     switch (theMenuItem) {
  107.     
  108.         case IDM_FILENEW:
  109.             QTFrame_CreateNewMovie();
  110.             break;
  111.  
  112.         case IDM_FILEOPEN:
  113.             OpenMovieInWindow(NULL, NULL);
  114.             break;
  115.  
  116.         case IDM_FILECLOSE:
  117.             QTFrame_DestroyMovieWindow(theWindow);
  118.             break;
  119.  
  120.         case IDM_FILESAVE:
  121.             QTFrame_UpdateMovieFile(theWindow);
  122.             break;
  123.  
  124.         case IDM_FILESAVEAS:
  125.             QTFrame_SaveAsMovieFile(theWindow);
  126.             break;
  127.             
  128.         case IDM_EXIT:
  129.             QTFrame_QuitFramework();
  130.             break;
  131.  
  132.         default:
  133.             break;
  134.     } // switch (theMenuItem)
  135.     
  136. }
  137.  
  138. //////////
  139. //
  140. // QTFrame_AdjustMenus 
  141. // Adjust the application's menus.
  142. //
  143. // On Windows, the theWindow parameter is a handle to the active MDI *child* window, if any.
  144. // On Mac, the theWindow parameter is a pointer to the frontmost window, if any.
  145. //
  146. //////////
  147.  
  148. int QTFrame_AdjustMenus (WindowReference theWindow, MenuReference theMenu)
  149. {
  150. #if TARGET_OS_MAC
  151. #pragma unused(theMenu)
  152. #endif
  153.  
  154.     WindowObject        myWindowObject = NULL; 
  155.     MovieController     myMC = NULL;
  156.     MenuReference        myMenu = NULL;
  157.     
  158. #if TARGET_OS_WIN32
  159.     myMenu = theMenu;
  160. #endif
  161.  
  162.     if (theWindow != NULL)
  163.         myWindowObject = QTFrame_GetWindowObjectFromWindow(theWindow);
  164.  
  165.     if (myWindowObject != NULL)
  166.         myMC = (**myWindowObject).fController;
  167.  
  168.     //////////
  169.     //
  170.     // configure the Edit menu
  171.     //
  172.     //////////
  173.     
  174. #if TARGET_OS_MAC
  175.     myMenu = GetMenuHandle(kEditMenuResID);
  176. #endif
  177.     if (myMC != NULL) {
  178.         long    myFlags;
  179.         
  180.         MCGetControllerInfo(myMC, &myFlags);
  181.     
  182.         QTFrame_SetMenuItemState(myMenu, IDM_EDITUNDO, myFlags & mcInfoUndoAvailable ? kEnableMenuItem : kDisableMenuItem);
  183.         QTFrame_SetMenuItemState(myMenu, IDM_EDITCUT, myFlags & mcInfoCutAvailable ? kEnableMenuItem : kDisableMenuItem);
  184.         QTFrame_SetMenuItemState(myMenu, IDM_EDITCOPY, myFlags & mcInfoCopyAvailable ? kEnableMenuItem : kDisableMenuItem);
  185.         QTFrame_SetMenuItemState(myMenu, IDM_EDITPASTE, myFlags & mcInfoPasteAvailable ? kEnableMenuItem : kDisableMenuItem);
  186.         QTFrame_SetMenuItemState(myMenu, IDM_EDITCLEAR, myFlags & mcInfoClearAvailable ? kEnableMenuItem : kDisableMenuItem);
  187.         QTFrame_SetMenuItemState(myMenu, IDM_EDITSELECTALL, myFlags & mcInfoEditingEnabled ? kEnableMenuItem : kDisableMenuItem);
  188.         QTFrame_SetMenuItemState(myMenu, IDM_EDITSELECTNONE, myFlags & mcInfoEditingEnabled ? kEnableMenuItem : kDisableMenuItem);
  189.     } else {
  190.         QTFrame_SetMenuItemState(myMenu, IDM_EDITUNDO, kDisableMenuItem);
  191.         QTFrame_SetMenuItemState(myMenu, IDM_EDITCUT, kDisableMenuItem);
  192.         QTFrame_SetMenuItemState(myMenu, IDM_EDITCOPY, kDisableMenuItem);
  193.         QTFrame_SetMenuItemState(myMenu, IDM_EDITPASTE, kDisableMenuItem);
  194.         QTFrame_SetMenuItemState(myMenu, IDM_EDITCLEAR, kDisableMenuItem);
  195.         QTFrame_SetMenuItemState(myMenu, IDM_EDITSELECTALL, kDisableMenuItem);
  196.         QTFrame_SetMenuItemState(myMenu, IDM_EDITSELECTNONE, kDisableMenuItem);
  197.     }
  198.  
  199.     //////////
  200.     //
  201.     // configure the File menu
  202.     //
  203.     //////////
  204.     
  205. #if TARGET_OS_MAC
  206.     myMenu = GetMenuHandle(kFileMenuResID);
  207. #endif
  208.     if (theWindow != NULL) {                // there is a window open
  209.         // handle the Close command
  210.         QTFrame_SetMenuItemState(myMenu, IDM_FILECLOSE, kEnableMenuItem);
  211.         
  212.         // handle the Save As and Save commands
  213.         if (myWindowObject != NULL) {
  214.             QTFrame_SetMenuItemState(myMenu, IDM_FILESAVEAS, kEnableMenuItem);
  215.             QTFrame_SetMenuItemState(myMenu, IDM_FILESAVE, (**myWindowObject).fIsDirty ? kEnableMenuItem : kDisableMenuItem);
  216.         } else {
  217.             QTFrame_SetMenuItemState(myMenu, IDM_FILESAVEAS, kDisableMenuItem);
  218.             QTFrame_SetMenuItemState(myMenu, IDM_FILESAVE, kDisableMenuItem);
  219.         }
  220.     
  221.     } else {                                // there is no window open    
  222.         QTFrame_SetMenuItemState(myMenu, IDM_FILESAVE, kDisableMenuItem);
  223.         QTFrame_SetMenuItemState(myMenu, IDM_FILESAVEAS, kDisableMenuItem);
  224.         QTFrame_SetMenuItemState(myMenu, IDM_FILECLOSE, kDisableMenuItem);        
  225.     }
  226.  
  227.     // adjust any application-specific menus
  228.     QTApp_AdjustMenus(theWindow, theMenu);
  229.  
  230.     return(0);
  231. }
  232.  
  233.  
  234. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  235. //
  236. // Movie-handling functions.
  237. //
  238. // Use these functions to create new movies, open existing movies, save movies, and so forth.
  239. //
  240. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  241.  
  242. //////////
  243. //
  244. // QTFrame_CreateNewMovie
  245. // Create a new movie in a window; returns true if successful.
  246. //
  247. // NOTE: There are several user interface issues that are blissfully ignored by this routine,
  248. // principally the preferred names and the on-screen locations of the new windows. 
  249. //
  250. //////////
  251.  
  252. Boolean QTFrame_CreateNewMovie (void)
  253. {
  254.     Movie                myMovie = NULL;
  255.     FSSpec                myFSSpec;
  256.     StringPtr             myName = QTUtils_ConvertCToPascalString(kNewMovieName);
  257.     
  258.     myMovie = NewMovie(newMovieActive);
  259.     if (myMovie == NULL)
  260.         return(false);
  261.     
  262.     // create a default FSSpec
  263.     FSMakeFSSpec(0, 0L, myName, &myFSSpec);
  264.     
  265.     free(myName);
  266.     
  267.     return(OpenMovieInWindow(myMovie, &myFSSpec));
  268. }
  269.  
  270. //////////
  271. //
  272. // QTFrame_SaveAsMovieFile
  273. // Save the movie in the specified window under a new name.
  274. //
  275. // Human interface guidelines for "Save As..." dictate that, if the user selects a new file name
  276. // for the current movie, then that new file shall become the active one. This means that we need
  277. // to close the current movie file and open the new one.
  278. //
  279. //////////
  280.  
  281. OSErr QTFrame_SaveAsMovieFile (WindowReference theWindow)
  282. {
  283.     WindowObject        myWindowObject = NULL;
  284.     Movie                 myMovie = NULL;
  285.     FSSpec                myFile;
  286.     Boolean                myIsSelected = false;
  287.     Boolean                myIsReplacing = false;    
  288.     StringPtr             myPrompt = QTUtils_ConvertCToPascalString(kSavePrompt);
  289.     StringPtr             myFileName = QTUtils_ConvertCToPascalString(kSaveMovieFileName);
  290.     OSErr                myErr = paramErr;
  291.     
  292.     // get the window object associated with the specified window
  293.     myWindowObject = QTFrame_GetWindowObjectFromWindow(theWindow);
  294.     if (myWindowObject == NULL)
  295.         goto bail;
  296.         
  297.     myMovie = (**myWindowObject).fMovie;
  298.     if (myMovie == NULL)
  299.         goto bail;
  300.         
  301.     QTFrame_PutFile(myPrompt, myFileName, &myFile, &myIsSelected, &myIsReplacing);
  302.     if (myIsSelected) {
  303.         Movie            myNewMovie = NULL;
  304.         MovieController    myMC = NULL;
  305.         long            myFlags;
  306.         short            myRefNum = kInvalidFileRefNum;
  307.         short            myResID = movieInDataForkResID;
  308.         
  309.         //////////
  310.         //
  311.         // we have a valid FSSpec for the new movie file; now we want to create a new movie file,
  312.         // save the movie data into the new file, close the existing movie file, and then swap
  313.         // the window object data
  314.         //
  315.         //////////
  316.         
  317.         // delete any existing file of that name
  318.         if (myIsReplacing) {
  319.             myErr = DeleteMovieFile(&myFile);
  320.             if (myErr != noErr)
  321.                 goto bail;
  322.         }
  323.         
  324.         myFlags = createMovieFileDeleteCurFile | createMovieFileDontOpenFile | createMovieFileDontCreateMovie | createMovieFileDontCreateResFile;
  325.         myErr = CreateMovieFile(&myFile, sigMoviePlayer, smSystemScript, myFlags, NULL, NULL);
  326.         if (myErr != noErr)
  327.             goto bail;
  328.         
  329.         myErr = OpenMovieFile(&myFile, &myRefNum, fsRdWrPerm);
  330.         if (myErr != noErr)
  331.             goto bail;
  332.             
  333.         // write existing movie's data into new movie file
  334.         myErr = AddMovieResource(myMovie, myRefNum, &myResID, myFile.name);
  335.         if (myErr != noErr)
  336.             goto bail;
  337.  
  338.         // get the new movie from the file
  339.         myErr = NewMovieFromFile(&myNewMovie, myRefNum, &myResID, NULL, newMovieActive, NULL);        
  340.         if (myErr != noErr)
  341.             goto bail;
  342.         
  343.         // create a new movie controller
  344.         myMC = CreateController(myNewMovie, theWindow, false);
  345.         
  346.         //////////
  347.         //
  348.         // if we got to here, we've successfully created a new movie file, and NewMovieFromFile has
  349.         // returned the new movie to us; so we need to close down the current movie and install the
  350.         // new movie in its place
  351.         //
  352.         //////////
  353.         
  354.         // close the existing movie file
  355.         if ((**myWindowObject).fFileRefNum != kInvalidFileRefNum)
  356.             CloseMovieFile((**myWindowObject).fFileRefNum);
  357.         
  358.         // dispose of the existing movie controller and movie resource
  359.         DisposeMovieController((**myWindowObject).fController);
  360.         DisposeMovie(myMovie);
  361.         
  362.         // keep track of the new info
  363.         (**myWindowObject).fMovie = myNewMovie;
  364.         (**myWindowObject).fController = myMC;
  365.         (**myWindowObject).fFileFSSpec = myFile;
  366.         (**myWindowObject).fFileResID = myResID;
  367.         (**myWindowObject).fFileRefNum = myRefNum;
  368.         (**myWindowObject).fIsDirty = false;
  369.  
  370.         // make sure the movie uses the window GWorld in all situations
  371.         SetMovieGWorld(myNewMovie, (CGrafPtr)QTFrame_GetPortFromWindowReference((**myWindowObject).fWindow), NULL);
  372.  
  373.         // set the window title
  374.         QTFrame_SetWindowTitleFromFSSpec(theWindow, &myFile, true);
  375.     } else {
  376.         myErr = userCanceledErr;
  377.     }
  378.  
  379. bail:
  380.     free(myPrompt);
  381.     free(myFileName);
  382.     
  383.     return(myErr);
  384. }
  385.  
  386.  
  387. //////////
  388. //
  389. // QTFrame_UpdateMovieFile
  390. // Update the file (if any) attached to the movie.
  391. //
  392. //////////
  393.  
  394. Boolean QTFrame_UpdateMovieFile (WindowReference theWindow)
  395. {
  396.     WindowObject        myWindowObject = NULL;
  397.     Movie                 myMovie = NULL;
  398.     OSErr                myErr = noErr;
  399.     
  400.     // get the window object associated with the specified window
  401.     myWindowObject = QTFrame_GetWindowObjectFromWindow(theWindow);
  402.     if (myWindowObject == NULL)
  403.         return(false);
  404.         
  405.     myMovie = (**myWindowObject).fMovie;
  406.     if (myMovie == NULL)
  407.         return(false);
  408.     
  409.     // update the current volume setting
  410.     QTUtils_UpdateMovieVolumeSetting(myMovie);
  411.     
  412.     if ((**myWindowObject).fFileRefNum == kInvalidFileRefNum)        // brand new movie, so no file attached to it
  413.         myErr = QTFrame_SaveAsMovieFile(theWindow);
  414.     else                                                            // we have an existing file; just update the movie resource
  415.         myErr = UpdateMovieResource(myMovie, (**myWindowObject).fFileRefNum, (**myWindowObject).fFileResID, NULL);
  416.     
  417.     (**myWindowObject).fIsDirty = false;
  418.  
  419.     return(myErr == noErr);
  420. }
  421.  
  422.  
  423. //////////
  424. //
  425. // QTFrame_IdleMovieWindows
  426. // Do idle-time processing on all open movie windows.
  427. //
  428. //////////
  429.  
  430. void QTFrame_IdleMovieWindows (void)
  431. {    
  432.     WindowReference            myWindow = NULL;
  433.     MovieController            myMC = NULL;
  434.     
  435.     myWindow = QTFrame_GetFrontMovieWindow();
  436.     while (myWindow != NULL) {
  437.         myMC = QTFrame_GetMCFromWindow(myWindow);
  438.         if (myMC != NULL)
  439.             MCIdle(myMC);
  440.             
  441.         QTApp_Idle(myWindow);
  442.         
  443.         myWindow = QTFrame_GetNextMovieWindow(myWindow);
  444.     }
  445. }
  446.  
  447.  
  448. //////////
  449. //
  450. // QTFrame_CloseMovieWindows
  451. // Close all open movie windows.
  452. //
  453. //////////
  454.  
  455. void QTFrame_CloseMovieWindows (void)
  456. {
  457. #if TARGET_OS_MAC    
  458.     WindowReference            myWindow = NULL;
  459.     WindowReference            myNextWindow = NULL;
  460.  
  461.     myWindow = QTFrame_GetFrontMovieWindow();
  462.     while (myWindow != NULL) {
  463.         myNextWindow = QTFrame_GetNextMovieWindow(myWindow);
  464.         QTFrame_DestroyMovieWindow(myWindow);
  465.         myWindow = myNextWindow;
  466.     }
  467. #endif
  468. #if TARGET_OS_WIN32
  469.     SendMessage(ghWnd, WM_COMMAND, (WPARAM)IDM_WINDOWCLOSEALL, 0L);
  470. #endif
  471. }
  472.  
  473.  
  474. //////////
  475. //
  476. // QTFrame_CreateWindowObject
  477. // Create a new window object associated with the specified window.
  478. //
  479. //////////
  480.  
  481. void QTFrame_CreateWindowObject (WindowReference theWindow)
  482. {
  483.     WindowObject            myWindowObject = NULL;
  484.  
  485.     if (theWindow == NULL)
  486.         return;
  487.         
  488.     // allocate space for a window object record and fill in some of its fields
  489.     myWindowObject = (WindowObject)NewHandleClear(sizeof(WindowObjectRecord));
  490.     if (myWindowObject != NULL) {
  491.         (**myWindowObject).fWindow = theWindow;
  492.         (**myWindowObject).fController = NULL;
  493.         (**myWindowObject).fObjectType = kApplicationSignature;
  494.         (**myWindowObject).fCanResizeWindow = true;
  495.         (**myWindowObject).fInstance = NULL;
  496.         (**myWindowObject).fIsDirty = false;
  497.         (**myWindowObject).fAppData = NULL;
  498.     }
  499.     
  500.     // associate myWindowObject (which may be NULL) with the window
  501. #if TARGET_OS_MAC
  502.     SetWRefCon(theWindow, (long)myWindowObject);
  503. #endif
  504. #if TARGET_OS_WIN32
  505.     SetWindowLong(theWindow, GWL_USERDATA, (LPARAM)myWindowObject);
  506.     
  507.     // associate a GrafPort with this window 
  508.     CreatePortAssociation(theWindow, NULL, 0L);
  509. #endif
  510.     
  511.     // set the current port to the new window
  512.     MacSetPort(QTFrame_GetPortFromWindowReference(theWindow));
  513. }
  514.  
  515.  
  516. //////////
  517. //
  518. // QTFrame_CloseWindowObject
  519. // Close a window object and any associated data.
  520. //
  521. //////////
  522.  
  523. void QTFrame_CloseWindowObject (WindowObject theWindowObject)
  524. {
  525.     if (theWindowObject == NULL)
  526.         return;
  527.         
  528.     // close the movie file
  529.     if ((**theWindowObject).fFileRefNum != kInvalidFileRefNum) {
  530.         CloseMovieFile((**theWindowObject).fFileRefNum);
  531.         (**theWindowObject).fFileRefNum = kInvalidFileRefNum;
  532.     }
  533.     
  534.     // dispose movie controller and movie 
  535.     if ((**theWindowObject).fController != NULL) {
  536.         MCSetActionFilterWithRefCon((**theWindowObject).fController, NULL, 0L);
  537.         DisposeMovieController((**theWindowObject).fController);
  538.         (**theWindowObject).fController = NULL;
  539.     }
  540.     
  541.     if ((**theWindowObject).fMovie != NULL) {
  542.         DisposeMovie((**theWindowObject).fMovie);
  543.         (**theWindowObject).fMovie = NULL;
  544.     }
  545.     
  546.     // close the graphics importer, if any
  547.     if ((**theWindowObject).fGraphicsImporter != NULL) {
  548.         CloseComponent((**theWindowObject).fGraphicsImporter);
  549.         (**theWindowObject).fGraphicsImporter = NULL;
  550.     }
  551.     
  552.     // do any application-specific window clean-up
  553.     QTApp_RemoveWindowObject(theWindowObject);
  554.     
  555.     DisposeHandle((Handle)theWindowObject);
  556. }
  557.  
  558.  
  559. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  560. //
  561. // Window-walking utilities.
  562. //
  563. // Use these functions to iterate through all windows or movie windows belonging to the application.
  564. //
  565. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  566.  
  567. //////////
  568. //
  569. // QTFrame_GetFrontAppWindow
  570. // Return a reference to the frontmost application window (whether or not it's a movie window).
  571. //
  572. //////////
  573.  
  574. WindowReference QTFrame_GetFrontAppWindow (void)
  575. {
  576. #if TARGET_OS_MAC
  577.     return(FrontWindow());
  578. #endif
  579. #if TARGET_OS_WIN32
  580.     return(GetWindow(ghWnd, GW_HWNDFIRST));
  581. #endif
  582. }
  583.  
  584.  
  585. //////////
  586. //
  587. // QTFrame_GetNextAppWindow
  588. // Return a reference to the next application window (whether or not it's a movie window).
  589. //
  590. //////////
  591.  
  592. WindowReference QTFrame_GetNextAppWindow (WindowReference theWindow)
  593. {
  594. #if TARGET_OS_MAC
  595.     return(theWindow == NULL ? NULL : GetNextWindow(theWindow));
  596. #endif
  597. #if TARGET_OS_WIN32
  598.     return(GetWindow(theWindow, GW_HWNDNEXT));
  599. #endif
  600. }
  601.  
  602.  
  603. //////////
  604. //
  605. // QTFrame_GetFrontMovieWindow
  606. // Return a reference to the frontmost movie window.
  607. //
  608. //////////
  609.  
  610. WindowReference QTFrame_GetFrontMovieWindow (void)
  611. {
  612.     WindowReference            myWindow;
  613.  
  614. #if TARGET_OS_MAC
  615.     myWindow = QTFrame_GetFrontAppWindow();
  616.     while ((myWindow != NULL) && (QTFrame_GetWindowObjectFromWindow(myWindow) == NULL))
  617.         myWindow = QTFrame_GetNextAppWindow(myWindow);
  618. #endif
  619.  
  620. #if TARGET_OS_WIN32
  621.     myWindow = (HWND)SendMessage(ghWndMDIClient, WM_MDIGETACTIVE, 0, 0L);
  622. #endif
  623.  
  624.     return(myWindow);
  625. }
  626.  
  627.  
  628. //////////
  629. //
  630. // QTFrame_GetNextMovieWindow
  631. // Return a reference to the next movie window.
  632. //
  633. //////////
  634.  
  635. WindowReference QTFrame_GetNextMovieWindow (WindowReference theWindow)
  636. {
  637.     WindowReference            myWindow;
  638.  
  639. #if TARGET_OS_MAC
  640.     myWindow = QTFrame_GetNextAppWindow(theWindow);
  641.     while ((myWindow != NULL) && (QTFrame_GetWindowObjectFromWindow(myWindow) == NULL))
  642.         myWindow = QTFrame_GetNextAppWindow(myWindow);
  643. #endif
  644.  
  645. #if TARGET_OS_WIN32
  646.     myWindow = GetWindow(theWindow, GW_HWNDNEXT);
  647. #endif
  648.  
  649.     return(myWindow);
  650. }
  651.  
  652.  
  653. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  654. //
  655. // Data-retrieval utilities.
  656. //
  657. // Use the following functions to retrieve the window object, the application-specific data, or the movie
  658. // controller that is associated with a window.
  659. //
  660. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  661.  
  662. //////////
  663. //
  664. // QTFrame_GetWindowObjectFromFrontWindow
  665. // Get the window object (if any) associated with the front window.
  666. //
  667. //////////
  668.  
  669. WindowObject QTFrame_GetWindowObjectFromFrontWindow (void)
  670. {
  671.     return(QTFrame_GetWindowObjectFromWindow(QTFrame_GetFrontMovieWindow()));
  672. }
  673.  
  674.  
  675. //////////
  676. //
  677. // QTFrame_GetWindowObjectFromWindow
  678. // Get the window object (if any) associated with the specified window.
  679. //
  680. //////////
  681.  
  682. WindowObject QTFrame_GetWindowObjectFromWindow (WindowReference theWindow)
  683. {
  684.     WindowObject        myWindowObject = NULL;
  685.  
  686.     if (!QTFrame_IsAppWindow(theWindow))
  687.         return(NULL);
  688.             
  689. #if TARGET_OS_MAC
  690.     myWindowObject = (WindowObject)GetWRefCon(theWindow);
  691. #endif
  692. #if TARGET_OS_WIN32
  693.     myWindowObject = (WindowObject)GetWindowLong(theWindow, GWL_USERDATA);
  694. #endif
  695.  
  696.     // make sure this is a window object
  697.     if (!QTFrame_IsWindowObjectOurs(myWindowObject))
  698.         return(NULL);
  699.         
  700.     return(myWindowObject);
  701. }
  702.  
  703.  
  704. //////////
  705. //
  706. // QTFrame_GetMCFromFrontWindow
  707. // Get the movie controller (if any) associated with the front window.
  708. //
  709. //////////
  710.  
  711. MovieController QTFrame_GetMCFromFrontWindow (void)
  712. {
  713.     return(QTFrame_GetMCFromWindow(QTFrame_GetFrontMovieWindow()));
  714. }
  715.  
  716.  
  717. //////////
  718. //
  719. // QTFrame_GetMCFromWindow
  720. // Get the movie controller (if any) associated with the specified window.
  721. //
  722. //////////
  723.  
  724. MovieController QTFrame_GetMCFromWindow (WindowReference theWindow)
  725. {
  726.     MovieController     myMC = NULL;
  727.     WindowObject        myWindowObject = NULL;
  728.         
  729.     myWindowObject = QTFrame_GetWindowObjectFromWindow(theWindow);
  730.     if (myWindowObject != NULL)
  731.         myMC = (**myWindowObject).fController;
  732.         
  733.     return(myMC);
  734. }
  735.  
  736.  
  737. //////////
  738. //
  739. // QTFrame_GetQTVRInstanceFromFrontWindow
  740. // Get the QTVRInstance (if any) associated with the front window.
  741. //
  742. //////////
  743.  
  744. QTVRInstance QTFrame_GetQTVRInstanceFromFrontWindow (void)
  745. {
  746.     return(QTFrame_GetQTVRInstanceFromWindow(QTFrame_GetFrontMovieWindow()));
  747. }
  748.  
  749.  
  750. //////////
  751. //
  752. // QTFrame_GetQTVRInstanceFromWindow
  753. // Get the QTVRInstance (if any) associated with the specified window.
  754. //
  755. //////////
  756.  
  757. QTVRInstance QTFrame_GetQTVRInstanceFromWindow (WindowReference theWindow)
  758. {
  759.     QTVRInstance         myInstance = NULL;
  760.     WindowObject        myWindowObject = NULL;
  761.     
  762.     myWindowObject = QTFrame_GetWindowObjectFromWindow(theWindow);
  763.     if (myWindowObject != NULL)
  764.         myInstance = (**myWindowObject).fInstance;
  765.         
  766.     return(myInstance);
  767. }
  768.  
  769.  
  770. //////////
  771. //
  772. // QTFrame_GetAppDataFromFrontWindow
  773. // Get the application-specific data associated with the front window.
  774. //
  775. //////////
  776.  
  777. Handle QTFrame_GetAppDataFromFrontWindow (void)
  778. {
  779.     return(QTFrame_GetAppDataFromWindow(QTFrame_GetFrontMovieWindow()));
  780. }
  781.  
  782.  
  783. //////////
  784. //
  785. // QTFrame_GetAppDataFromWindow
  786. // Get the application-specific data associated with the specified window.
  787. //
  788. //////////
  789.  
  790. Handle QTFrame_GetAppDataFromWindow (WindowReference theWindow)
  791. {
  792.     WindowObject        myWindowObject = NULL;
  793.     
  794.     myWindowObject = QTFrame_GetWindowObjectFromWindow(theWindow);
  795.     if (myWindowObject == NULL)
  796.         return(NULL);
  797.         
  798.     return(QTFrame_GetAppDataFromWindowObject(myWindowObject));
  799. }
  800.  
  801.  
  802. //////////
  803. //
  804. // QTFrame_GetAppDataFromWindowObject
  805. // Get the application-specific data associated with the specified window object.
  806. //
  807. //////////
  808.  
  809. Handle QTFrame_GetAppDataFromWindowObject (WindowObject theWindowObject)
  810. {
  811.     // make sure this is a window object belonging to our application
  812.     if (!QTFrame_IsWindowObjectOurs(theWindowObject))
  813.         return(NULL);
  814.     
  815.     return((**theWindowObject).fAppData);
  816. }
  817.  
  818.  
  819. //////////
  820. //
  821. // QTFrame_IsWindowObjectOurs
  822. // Does the specified window object belong to our application?
  823. //
  824. //////////
  825.  
  826. Boolean QTFrame_IsWindowObjectOurs (WindowObject theWindowObject)
  827. {
  828.     OSType        myType = 0L;
  829.  
  830.     if ((theWindowObject == NULL) || (*theWindowObject == NULL))
  831.         return(false);
  832.         
  833.     myType = (**theWindowObject).fObjectType;
  834.     return(myType == kApplicationSignature);
  835. }
  836.  
  837.  
  838. //////////
  839. //
  840. // QTFrame_IsAppWindow
  841. // Does the specified window belong to our application?
  842. //
  843. //////////
  844.  
  845. Boolean QTFrame_IsAppWindow (WindowReference theWindow)
  846. {
  847.     if (theWindow == NULL)
  848.         return(false);
  849.  
  850. #if TARGET_OS_MAC
  851.     return(GetWindowKind(theWindow) >= kApplicationWindowKind);
  852. #endif
  853. #if TARGET_OS_WIN32
  854.     return(true);
  855. #endif
  856. }
  857.  
  858.  
  859. //////////
  860. //
  861. // QTFrame_IsDocWindow
  862. // Is the specified window a document window (having a WindowObject refcon)?
  863. //
  864. //////////
  865.  
  866. Boolean QTFrame_IsDocWindow (WindowReference theWindow)
  867. {
  868.     if (theWindow == NULL)
  869.         return(false);
  870.  
  871. #if TARGET_OS_MAC
  872.     return(GetWindowKind(theWindow) >= kApplicationWindowKind);
  873. #endif
  874. #if TARGET_OS_WIN32
  875.     return(true);
  876. #endif
  877. }
  878.  
  879. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  880. //
  881. // Miscellaneous utilities.
  882. //
  883. // Use the following functions to play beeps, manipulate menus, and do other miscellaneous things.
  884. //
  885. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  886.  
  887. //////////
  888. //
  889. // QTFrame_Beep
  890. // Beep.
  891. //
  892. //////////
  893.  
  894. void QTFrame_Beep (void)
  895. {
  896. #if TARGET_OS_MAC
  897.     SysBeep(30);
  898. #endif
  899. #if TARGET_OS_WIN32
  900.     MessageBeep(MB_OK);
  901. #endif
  902. }
  903.  
  904.  
  905. //////////
  906. //
  907. // QTFrame_SetMenuState
  908. // Set the enabled/disabled state of a menu.
  909. //
  910. // On Windows, the theMenuItem parameter must be the (0-based) index in the menu bar of the
  911. // desired pull-down menu.
  912. //
  913. //////////
  914.  
  915. void QTFrame_SetMenuState (MenuReference theMenu, UInt16 theMenuItem, short theState)
  916. {
  917. #if TARGET_OS_MAC
  918. #pragma unused(theMenuItem)
  919.     QTFrame_SetMenuItemState(theMenu, 0, theState);        // menu item == 0 means the entire menu
  920. #endif
  921. #if TARGET_OS_WIN32
  922.     QTFrame_SetMenuItemState(theMenu, theMenuItem, theState | MF_BYPOSITION);
  923. #endif
  924. }
  925.  
  926.  
  927. //////////
  928. //
  929. // QTFrame_SetMenuItemState
  930. // Set the enabled/disabled state of a menu item.
  931. //
  932. // When running under MacOS 8.5.1, EnableMenuItem and DisableMenuItem seem to do nasty things
  933. // to the keyboard equivalents associated with a menu; so we'll work around that problem here.
  934. //
  935. //////////
  936.  
  937. void QTFrame_SetMenuItemState (MenuReference theMenu, UInt16 theMenuItem, short theState)
  938. {
  939. #if TARGET_OS_MAC
  940.     UInt8        myModifiers;
  941.     
  942.     // get the existing menu item modifiers
  943.     GetMenuItemModifiers(theMenu, MENU_ITEM(theMenuItem), &myModifiers);
  944.     
  945.     if (theState == kEnableMenuItem)
  946.         EnableMenuItem(theMenu, MENU_ITEM(theMenuItem));
  947.     else
  948.         DisableMenuItem(theMenu, MENU_ITEM(theMenuItem));
  949.         
  950.     // restore the previous menu item modifiers
  951.     SetMenuItemModifiers(theMenu, MENU_ITEM(theMenuItem), myModifiers);
  952. #endif
  953. #if TARGET_OS_WIN32
  954.     EnableMenuItem(theMenu, (UINT)theMenuItem, (UINT)theState);
  955. #endif
  956. }
  957.  
  958.  
  959. //////////
  960. //
  961. // QTFrame_SetMenuItemLabel
  962. // Set the label (that is, the text) of a menu item.
  963. //
  964. //////////
  965.  
  966. void QTFrame_SetMenuItemLabel (MenuReference theMenu, UInt16 theMenuItem, char *theText)
  967. {
  968. #if TARGET_OS_MAC
  969.     Str255        myString;
  970.     short        mySIndex, myTIndex;
  971.  
  972.     // we need to remove the '&' character while converting to a Pascal string    
  973.     mySIndex = 1;
  974.     for (myTIndex = 0; myTIndex < strlen(theText); myTIndex++) {
  975.         if (theText[myTIndex] != '&') {
  976.             myString[mySIndex] = theText[myTIndex];
  977.             mySIndex++;
  978.         }
  979.     }
  980.     
  981.     myString[0] = mySIndex - 1;
  982.     
  983.     SetMenuItemText(theMenu, MENU_ITEM(theMenuItem), myString);
  984. #endif
  985. #if TARGET_OS_WIN32
  986.     UINT        myState;
  987.     
  988.     // make sure that we preserve the current menu state
  989.     myState = GetMenuState(theMenu, (UINT)theMenuItem, MF_BYCOMMAND);
  990.     ModifyMenu(theMenu, (UINT)theMenuItem, MF_BYCOMMAND | MF_STRING | myState, (UINT)theMenuItem, (LPSTR)theText);
  991. #endif
  992. }
  993.  
  994.  
  995. //////////
  996. //
  997. // QTFrame_SetMenuItemCheck
  998. // Set the check mark state state of a menu item.
  999. //
  1000. //////////
  1001.  
  1002. void QTFrame_SetMenuItemCheck (MenuReference theMenu, UInt16 theMenuItem, Boolean theState)
  1003. {
  1004. #if TARGET_OS_MAC
  1005.     MacCheckMenuItem(theMenu, MENU_ITEM(theMenuItem), theState);
  1006. #endif
  1007. #if TARGET_OS_WIN32
  1008.     CheckMenuItem(theMenu, (UINT)theMenuItem, theState ? MF_CHECKED : MF_UNCHECKED);
  1009. #endif
  1010. }
  1011.  
  1012.  
  1013. //////////
  1014. //
  1015. // QTFrame_GetPortFromWindowReference 
  1016. // Return the graphics port associated with a window reference.
  1017. //
  1018. //////////
  1019.  
  1020. GrafPtr QTFrame_GetPortFromWindowReference (WindowReference theWindow)
  1021. {
  1022. #if TARGET_OS_MAC
  1023.     return((GrafPtr)GetWindowPort(theWindow));
  1024. #endif
  1025. #if TARGET_OS_WIN32
  1026.     return(GetNativeWindowPort(theWindow));
  1027. #endif
  1028. }
  1029.  
  1030.  
  1031. //////////
  1032. //
  1033. // QTFrame_GetWindowReferenceFromPort
  1034. // Return the window reference associated with a graphics port.
  1035. //
  1036. //////////
  1037.  
  1038. WindowReference QTFrame_GetWindowReferenceFromPort (GrafPtr thePort)
  1039. {
  1040. #if TARGET_OS_MAC
  1041.     return((WindowReference)GetWindowFromPort((CGrafPtr)thePort));
  1042. #endif
  1043. #if TARGET_OS_WIN32
  1044.     return((WindowReference)GetPortNativeWindow(thePort));
  1045. #endif
  1046. }
  1047.  
  1048.  
  1049. //////////
  1050. //
  1051. // QTFrame_GetWindowFromWindowReference
  1052. // Return the Macintosh window associated with a window reference.
  1053. //
  1054. //////////
  1055.  
  1056. WindowPtr QTFrame_GetWindowFromWindowReference (WindowReference theWindow)
  1057. {
  1058. #if TARGET_OS_MAC
  1059.     return((WindowPtr)theWindow);
  1060. #endif
  1061. #if TARGET_OS_WIN32
  1062.     return((WindowPtr)GetNativeWindowPort(theWindow));
  1063. #endif
  1064. }
  1065.  
  1066.  
  1067. /////////
  1068. //
  1069. // QTFrame_GetWindowWidth
  1070. // Return the width of the specified window.
  1071. //
  1072. //////////
  1073.  
  1074. short QTFrame_GetWindowWidth (WindowReference theWindow)
  1075. {
  1076. #if TARGET_OS_MAC
  1077.     Rect        myRect = {0, 0, 0, 0};
  1078.  
  1079.     if (theWindow != NULL)
  1080.         GetWindowPortBounds(theWindow, &myRect);
  1081. #endif
  1082. #if TARGET_OS_WIN32
  1083.     RECT        myRect = {0L, 0L, 0L, 0L};
  1084.  
  1085.     if (theWindow != NULL)
  1086.         GetWindowRect(theWindow, &myRect);
  1087. #endif
  1088.  
  1089.     return((short)(myRect.right - myRect.left));
  1090. }
  1091.  
  1092.  
  1093. //////////
  1094. //
  1095. // QTFrame_SetWindowTitleFromFSSpec
  1096. // Set the title of the specified window, using the name contained in the specified FSSpec.
  1097. //
  1098. //////////
  1099.  
  1100. void QTFrame_SetWindowTitleFromFSSpec (WindowReference theWindow, FSSpecPtr theFSSpecPtr, Boolean theAddToRecentDocs)
  1101. {
  1102. #if TARGET_OS_MAC
  1103. #pragma unused(theAddToRecentDocs)
  1104.     SetWTitle(theWindow, theFSSpecPtr->name);
  1105. #endif
  1106. #if TARGET_OS_WIN32
  1107.     char    *myTempName;
  1108.     char    myWindName[MAX_PATH];
  1109.  
  1110.     // get the full pathname contained in the FSSpec (which is a Str255)
  1111.     myTempName = QTUtils_ConvertPascalToCString(theFSSpecPtr->name);
  1112.  
  1113.     // get the movie file name from the full pathname
  1114.     QTFrame_GetDisplayName(myTempName, myWindName);
  1115.  
  1116.     // set the window title
  1117.     SetWindowText(theWindow, myWindName);
  1118.     
  1119.     // add this document to the Documents list, if so instructed
  1120.     if (theAddToRecentDocs)
  1121.         SHAddToRecentDocs(SHARD_PATH, myTempName);
  1122.     
  1123.     free(myTempName);
  1124. #endif
  1125. }
  1126.  
  1127.  
  1128. //////////
  1129. //
  1130. // QTFrame_SizeWindowToMovie
  1131. // Set the window size to exactly fit the movie and controller (if visible).
  1132. //
  1133. //////////
  1134.  
  1135. void QTFrame_SizeWindowToMovie (WindowObject theWindowObject)
  1136. {
  1137.     Rect                    myMovieBounds;
  1138.     Movie                    myMovie = NULL;
  1139.     MovieController            myMC = NULL;
  1140.     GraphicsImportComponent    myImporter = NULL;
  1141.  
  1142. #if TARGET_OS_WIN32
  1143.     gWeAreSizingWindow = true;
  1144. #endif
  1145.  
  1146.     if (theWindowObject == NULL)
  1147.         goto bail;
  1148.     
  1149.     myMovie = (**theWindowObject).fMovie;
  1150.     myMC = (**theWindowObject).fController;
  1151.     myImporter = (**theWindowObject).fGraphicsImporter;
  1152.  
  1153.     if (myImporter != NULL) {
  1154.         GraphicsImportGetBoundsRect(myImporter, &myMovieBounds);
  1155.         goto gotBounds;
  1156.     }
  1157.  
  1158.     if (myMovie == NULL)
  1159.         return;
  1160.  
  1161.     GetMovieBox(myMovie, &myMovieBounds);
  1162.  
  1163.     if (myMC != NULL)
  1164.         if (MCGetVisible(myMC))
  1165.             MCGetControllerBoundsRect(myMC, &myMovieBounds);
  1166.     
  1167.     // make sure that the movie has a non-zero width;
  1168.     // a zero height is okay (for example, with a music movie with no controller bar)
  1169.     if (myMovieBounds.right - myMovieBounds.left == 0) {
  1170.         myMovieBounds.left = 0;
  1171.         myMovieBounds.right = QTFrame_GetWindowWidth((**theWindowObject).fWindow);
  1172.     }
  1173.  
  1174. gotBounds:    
  1175.     SizeWindow(QTFrame_GetWindowFromWindowReference((**theWindowObject).fWindow),
  1176.                                             myMovieBounds.right - myMovieBounds.left,
  1177.                                             myMovieBounds.bottom - myMovieBounds.top,
  1178.                                             true);
  1179.  
  1180. bail:                                        
  1181. #if TARGET_OS_WIN32
  1182.     gWeAreSizingWindow = false;
  1183. #endif
  1184.  
  1185.     return;
  1186. }
  1187.  
  1188.  
  1189. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  1190. //
  1191. // File-opening and -saving utilities.
  1192. //
  1193. // The functions are meant to provide replacements for StandardGetFilePreview and StandardPutFile, which
  1194. // are not supported under Carbon. However, Navigation Services is not (yet, at any rate) supported under
  1195. // Windows, so we still need to call through to the Standard File Package.
  1196. //
  1197. // The Navigation Services portion of this code is based selectively on the file NavigationServicesSupport.c
  1198. // by Yan Arrouye and on the developer documentation "Programming With Navigation Services 1.1". The code that
  1199. // determines which files can be opened by QuickTime is based on code by Sam Bushell in CarbonMovieEditor.c.
  1200. //
  1201. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  1202.  
  1203. //////////
  1204. //
  1205. // QTFrame_PutFile
  1206. // Save a file under the specified name. Return Boolean values indicating whether the user selected a file
  1207. // and whether the selected file is replacing an existing file.
  1208. //
  1209. //////////
  1210.  
  1211. OSErr QTFrame_PutFile (ConstStr255Param thePrompt, ConstStr255Param theFileName, FSSpecPtr theFSSpecPtr, Boolean *theIsSelected, Boolean *theIsReplacing)
  1212. {
  1213. #if TARGET_OS_WIN32
  1214.     StandardFileReply    myReply;
  1215. #endif
  1216. #if TARGET_OS_MAC
  1217.     NavReplyRecord        myReply;
  1218.     NavDialogOptions    myDialogOptions;
  1219.     NavEventUPP            myEventUPP = NewNavEventProc(QTFrame_HandleNavEvent);
  1220. #endif
  1221.     OSErr                myErr = noErr;
  1222.  
  1223.     if ((theFSSpecPtr == NULL) || (theIsSelected == NULL) || (theIsReplacing == NULL))
  1224.         return(paramErr);
  1225.     
  1226.     // deactivate any frontmost movie window
  1227.     ActivateController(QTFrame_GetFrontMovieWindow(), false);
  1228.  
  1229.     // assume we are not replacing an existing file
  1230.     *theIsReplacing = false;
  1231.     
  1232. #if TARGET_OS_WIN32
  1233.     StandardPutFile(thePrompt, theFileName, &myReply);
  1234.     *theFSSpecPtr = myReply.sfFile;
  1235.     *theIsSelected = myReply.sfGood;
  1236.     if (myReply.sfGood)
  1237.         *theIsReplacing = myReply.sfReplacing;
  1238. #endif
  1239.  
  1240. #if TARGET_OS_MAC
  1241.     // specify the options for the dialog box
  1242.     NavGetDefaultDialogOptions(&myDialogOptions);
  1243.     myDialogOptions.dialogOptionFlags += kNavNoTypePopup;
  1244.     myDialogOptions.dialogOptionFlags += kNavDontAutoTranslate;
  1245.     BlockMoveData(theFileName, myDialogOptions.savedFileName, theFileName[0] + 1);
  1246.     BlockMoveData(gAppName, myDialogOptions.clientName, gAppName[0] + 1);
  1247.     BlockMoveData(thePrompt, myDialogOptions.message, thePrompt[0] + 1);
  1248.     
  1249.     // prompt the user for a file
  1250.     myErr = NavPutFile(NULL, &myReply, &myDialogOptions, myEventUPP, MovieFileType, sigMoviePlayer, NULL);
  1251.     if ((myErr == noErr) && myReply.validRecord) {
  1252.         AEKeyword        myKeyword;
  1253.         DescType        myActualType;
  1254.         Size            myActualSize = 0;
  1255.         
  1256.         // get the FSSpec for the selected file
  1257.         if (theFSSpecPtr != NULL)
  1258.             myErr = AEGetNthPtr(&(myReply.selection), 1, typeFSS, &myKeyword, &myActualType, theFSSpecPtr, sizeof(FSSpec), &myActualSize);
  1259.  
  1260.         NavDisposeReply(&myReply);
  1261.     }
  1262.         
  1263.     *theIsSelected = myReply.validRecord;
  1264.     if (myReply.validRecord)
  1265.         *theIsReplacing = myReply.replacing;
  1266.  
  1267.     DisposeNavEventUPP(myEventUPP);
  1268. #endif
  1269.  
  1270.     return(myErr);
  1271. }
  1272.     
  1273.  
  1274. //////////
  1275. //
  1276. // QTFrame_GetOneFileWithPreview
  1277. // Display the appropriate file-opening dialog box, with an optional QuickTime preview pane. If the user
  1278. // selects a file, return information about it using the theFSSpecPtr parameter.
  1279. //
  1280. // Note that both StandardGetFilePreview and NavGetFile use the function specified by theFilterProc as a
  1281. // file filter. This framework always passes NULL in the theFilterProc parameter. If you use this function
  1282. // in your own code, keep in mind that on Windows the function specifier must be of type FileFilterUPP and 
  1283. // on Macintosh it must be of type NavObjectFilterUPP. (You can use the QTFrame_GetFileFilterUPP to create
  1284. // a function specifier of the appropriate type.) Also keep in mind that Navigation Services expects a file 
  1285. // filter function to return true if a file is to be displayed, while the Standard File Package expects the
  1286. // filter to return false if a file is to be displayed.
  1287. //
  1288. //////////
  1289.  
  1290. OSErr QTFrame_GetOneFileWithPreview (short theNumTypes, QTFrameTypeListPtr theTypeList, FSSpecPtr theFSSpecPtr, void *theFilterProc)
  1291. {
  1292. #if TARGET_OS_WIN32
  1293.     StandardFileReply    myReply;
  1294. #endif
  1295. #if TARGET_OS_MAC
  1296.     NavReplyRecord        myReply;
  1297.     NavDialogOptions    myDialogOptions;
  1298.     NavTypeListHandle    myOpenList = NULL;
  1299.     NavEventUPP            myEventUPP = NewNavEventProc(QTFrame_HandleNavEvent);
  1300. #endif
  1301.     OSErr                myErr = noErr;
  1302.     
  1303.     if (theFSSpecPtr == NULL)
  1304.         return(paramErr);
  1305.     
  1306.     // deactivate any frontmost movie window
  1307.     ActivateController(QTFrame_GetFrontMovieWindow(), false);
  1308.  
  1309. #if TARGET_OS_WIN32
  1310.     // prompt the user for a file
  1311.     StandardGetFilePreview((FileFilterUPP)theFilterProc, theNumTypes, (ConstSFTypeListPtr)theTypeList, &myReply);
  1312.     if (!myReply.sfGood)
  1313.         return(userCanceledErr);
  1314.     
  1315.     // make an FSSpec record
  1316.     myErr = FSMakeFSSpec(myReply.sfFile.vRefNum, myReply.sfFile.parID, myReply.sfFile.name, theFSSpecPtr);
  1317. #endif
  1318.  
  1319. #if TARGET_OS_MAC
  1320.     // specify the options for the dialog box
  1321.     NavGetDefaultDialogOptions(&myDialogOptions);
  1322.     myDialogOptions.dialogOptionFlags -= kNavNoTypePopup;
  1323.     myDialogOptions.dialogOptionFlags -= kNavAllowMultipleFiles;
  1324.     BlockMoveData(gAppName, myDialogOptions.clientName, gAppName[0] + 1);
  1325.     
  1326.     // create a handle to an 'open' resource
  1327.     myOpenList = (NavTypeListHandle)QTFrame_CreateOpenHandle(kApplicationSignature, theNumTypes, theTypeList);
  1328.     if (myOpenList != NULL)
  1329.         HLock((Handle)myOpenList);
  1330.     
  1331.     // prompt the user for a file
  1332.     myErr = NavGetFile(NULL, &myReply, &myDialogOptions, myEventUPP, NULL, (NavObjectFilterUPP)theFilterProc, myOpenList, NULL);
  1333.     if ((myErr == noErr) && myReply.validRecord) {
  1334.         AEKeyword        myKeyword;
  1335.         DescType        myActualType;
  1336.         Size            myActualSize = 0;
  1337.         
  1338.         // get the FSSpec for the selected file
  1339.         if (theFSSpecPtr != NULL)
  1340.             myErr = AEGetNthPtr(&(myReply.selection), 1, typeFSS, &myKeyword, &myActualType, theFSSpecPtr, sizeof(FSSpec), &myActualSize);
  1341.  
  1342.         NavDisposeReply(&myReply);
  1343.     }
  1344.     
  1345.     if (myOpenList != NULL) {
  1346.         HUnlock((Handle)myOpenList);
  1347.         DisposeHandle((Handle)myOpenList);
  1348.     }
  1349.     
  1350.     DisposeNavEventUPP(myEventUPP);
  1351. #endif
  1352.  
  1353.     return(myErr);
  1354. }
  1355.  
  1356.  
  1357. //////////
  1358. //
  1359. // QTFrame_HandleNavEvent
  1360. // A callback procedure that handles events while a Navigation Service dialog box is displayed.
  1361. //
  1362. //////////
  1363.  
  1364. PASCAL_RTN void QTFrame_HandleNavEvent (NavEventCallbackMessage theCallBackSelector, NavCBRecPtr theCallBackParms, void *theCallBackUD)
  1365. {
  1366. #pragma unused(theCallBackUD)
  1367.     WindowReference        myWindow = NULL;    
  1368.     
  1369.     if (theCallBackSelector == kNavCBEvent) {
  1370.         switch (theCallBackParms->eventData.eventDataParms.event->what) {
  1371.             case updateEvt:
  1372. #if TARGET_OS_MAC
  1373.                 QTFrame_HandleEvent(theCallBackParms->eventData.eventDataParms.event);
  1374. #endif
  1375.                 break;
  1376.             case nullEvent:
  1377.                 QTFrame_IdleMovieWindows();
  1378.                 break;
  1379.         }
  1380.     }
  1381. }
  1382.  
  1383.  
  1384. //////////
  1385. //
  1386. // QTFrame_CreateOpenHandle
  1387. // Return a handle to a dynamically-created 'open' resource.
  1388. //
  1389. //////////
  1390.  
  1391. Handle QTFrame_CreateOpenHandle (OSType theApplicationSignature, short theNumTypes, QTFrameTypeListPtr theTypeList)
  1392. {
  1393.     Handle            myHandle = NULL;
  1394.     
  1395.     if (theTypeList == NULL)
  1396.         return(myHandle);
  1397.     
  1398.     if (theNumTypes > 0) {
  1399.         myHandle = NewHandle(sizeof(NavTypeList) + (theNumTypes * sizeof(OSType)));
  1400.         if (myHandle != NULL) {
  1401.             NavTypeListHandle     myOpenResHandle    = (NavTypeListHandle)myHandle;
  1402.             
  1403.             (*myOpenResHandle)->componentSignature = theApplicationSignature;
  1404.             (*myOpenResHandle)->osTypeCount = theNumTypes;
  1405.             BlockMoveData(theTypeList, (*myOpenResHandle)->osType, theNumTypes * sizeof(OSType));
  1406.         }
  1407.     }
  1408.     
  1409.     return(myHandle);
  1410. }
  1411.  
  1412.  
  1413. //////////
  1414. //
  1415. // QTFrame_GetFileFilterUPP
  1416. // Return a UPP for the specified file-selection filter function.
  1417. //
  1418. // The caller is responsible for disposing of the UPP returned by this function (by calling DisposeRoutineDescriptor).
  1419. //
  1420. //////////
  1421.  
  1422. QTFrameFileFilterUPP QTFrame_GetFileFilterUPP (ProcPtr theFileFilterProc)
  1423. {
  1424. #if TARGET_OS_MAC
  1425.     return(NewNavObjectFilterUPP((NavObjectFilterProcPtr)theFileFilterProc));
  1426. #endif
  1427. #if TARGET_OS_WIN32
  1428.     return(NewFileFilterProc(theFileFilterProc));
  1429. #endif
  1430. }
  1431.  
  1432.  
  1433. //////////
  1434. //
  1435. // QTFrame_FilterFiles
  1436. // Filter files for a file-opening dialog box.
  1437. //
  1438. // The default behavior here is to accept all files that can be opened by QuickTime, whether directly
  1439. // or using a movie importer or a graphics importer.
  1440. //
  1441. //////////
  1442.  
  1443. #if TARGET_OS_MAC
  1444. PASCAL_RTN Boolean QTFrame_FilterFiles (AEDesc *theItem, void *theInfo, void *theCallBackUD, NavFilterModes theFilterMode)
  1445. {
  1446. #pragma unused(theCallBackUD, theFilterMode)
  1447.     NavFileOrFolderInfo        *myInfo = (NavFileOrFolderInfo *)theInfo;
  1448.     
  1449.     if (gValidFileTypes == NULL)
  1450.         QTFrame_BuildFileTypeList();
  1451.  
  1452.     if (theItem->descriptorType == typeFSS) {
  1453.         if (!myInfo->isFolder) {
  1454.             OSType            myType = myInfo->fileAndFolder.fileInfo.finderInfo.fdType;
  1455.             short            myCount;
  1456.             short            myIndex;
  1457.             
  1458.             // see whether the file type is in the list of file types that our application can open 
  1459.             myCount = GetPtrSize((Ptr)gValidFileTypes) / sizeof(OSType);
  1460.             for (myIndex = 0; myIndex < myCount; myIndex++)
  1461.                 if (myType == gValidFileTypes[myIndex])
  1462.                     return(true);
  1463.  
  1464.             // if we got to here, it's a file we cannot open
  1465.             return(false);        
  1466.         }
  1467.     }
  1468.     
  1469.     // if we got to here, it's a folder or non-HFS object
  1470.     return(true);
  1471. }
  1472. #endif
  1473. #if TARGET_OS_WIN32
  1474. PASCAL_RTN Boolean QTFrame_FilterFiles (CInfoPBPtr thePBPtr)
  1475. {
  1476. #pragma unused(thePBPtr)
  1477.     return(false);
  1478. }
  1479. #endif
  1480.  
  1481.  
  1482. //////////
  1483. //
  1484. // QTFrame_BuildFileTypeList
  1485. // Build a list of file types that QuickTime can open.
  1486. //
  1487. //////////
  1488.  
  1489. OSErr QTFrame_BuildFileTypeList (void)
  1490. {
  1491.     long        myIndex = 0;
  1492.     OSErr        myErr = noErr;
  1493.  
  1494.     // if we've already built the list, just return
  1495.     if (gValidFileTypes != NULL)
  1496.         return(myErr);
  1497.     
  1498.     // allocate a block of memory to hold a preset number of file types; we'll resize this block
  1499.     // while building the list if we need more room; we always resize it after building the list,
  1500.     // to truncate it to the exact size required
  1501.     gValidFileTypes = (OSType *)NewPtrClear(sizeof(OSType) * kDefaultFileTypeCount);
  1502.     if (gValidFileTypes == NULL)
  1503.         return(memFullErr);
  1504.     
  1505.     // we can open any files of type kQTFileTypeMovie
  1506.     gValidFileTypes[myIndex++] = kQTFileTypeMovie;
  1507.     
  1508.     // we can open any files for which QuickTime supplies a movie importer component
  1509.     QTFrame_AddComponentFileTypes(MovieImportType, &myIndex);
  1510.     
  1511.     // we can open any files for which QuickTime supplies a graphics importer component
  1512.     QTFrame_AddComponentFileTypes(GraphicsImporterComponentType, &myIndex);
  1513.  
  1514.     // resize the pointer to hold the exact number of valid file types
  1515.     SetPtrSize((Ptr)gValidFileTypes, myIndex * sizeof(OSType));
  1516.     myErr = MemError();
  1517.     
  1518.     return(myErr);
  1519. }
  1520.  
  1521.  
  1522. //////////
  1523. //
  1524. // QTFrame_AddComponentFileTypes
  1525. // Add all subtypes of the specified component type to the global list of file types.
  1526. //
  1527. //////////
  1528.  
  1529. static void QTFrame_AddComponentFileTypes (OSType theComponentType, long *theNextIndex)
  1530. {
  1531.     ComponentDescription        myFindCompDesc = {0, 0, 0, 0, 0};
  1532.     ComponentDescription        myInfoCompDesc = {0, 0, 0, 0, 0};
  1533.     Component                    myComponent = NULL;
  1534.  
  1535.     myFindCompDesc.componentType = theComponentType;
  1536.     myFindCompDesc.componentFlags = 0;
  1537.     myFindCompDesc.componentFlagsMask = movieImportSubTypeIsFileExtension;
  1538.  
  1539.     myComponent = FindNextComponent(myComponent, &myFindCompDesc);
  1540.     while (myComponent != NULL) {
  1541.         GetComponentInfo(myComponent, &myInfoCompDesc, NULL, NULL, NULL);
  1542.         gValidFileTypes[*theNextIndex] = myInfoCompDesc.componentSubType;
  1543.         *theNextIndex += 1;
  1544.         
  1545.         // resize the block of file types, if we are about to reach the limit
  1546.         if (*theNextIndex == GetPtrSize((Ptr)gValidFileTypes) / (long)sizeof(OSType)) {
  1547.             SetPtrSize((Ptr)gValidFileTypes, GetPtrSize((Ptr)gValidFileTypes) + (kDefaultFileTypeCount * sizeof(OSType)));
  1548.             if (MemError() != noErr)
  1549.                 return;
  1550.         }
  1551.         
  1552.         myComponent = FindNextComponent(myComponent, &myFindCompDesc);
  1553.     }
  1554. }
  1555.  
  1556.  
  1557. #if TARGET_OS_WIN32
  1558. //////////
  1559. //
  1560. // QTFrame_ConvertMacToWinRect
  1561. // Convert a Macintosh Rect structure into a Windows RECT structure.
  1562. //
  1563. //////////
  1564.  
  1565. void QTFrame_ConvertMacToWinRect (Rect *theMacRect, RECT *theWinRect)
  1566. {
  1567.     theWinRect->top = (long)theMacRect->top;
  1568.     theWinRect->left = (long)theMacRect->left;
  1569.     theWinRect->bottom = (long)theMacRect->bottom;
  1570.     theWinRect->right = (long)theMacRect->right;
  1571. }
  1572.  
  1573.  
  1574. //////////
  1575. //
  1576. // QTFrame_ConvertWinToMacRect
  1577. // Convert a Windows RECT structure into a Macintosh Rect structure.
  1578. //
  1579. //////////
  1580.  
  1581. void QTFrame_ConvertWinToMacRect (RECT *theWinRect, Rect *theMacRect)
  1582. {
  1583.     theMacRect->top = (short)theWinRect->top;
  1584.     theMacRect->left = (short)theWinRect->left;
  1585.     theMacRect->bottom = (short)theWinRect->bottom;
  1586.     theMacRect->right = (short)theWinRect->right;
  1587. }
  1588. #endif
  1589.